﻿ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.UserSkins;
using DevExpress.XtraBars.Helpers;

namespace QLMBMT
{
    public partial class FrmMain : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        public bool CheckExistForm(DevExpress.XtraEditors.XtraForm Form)
        {
            foreach (var child in MdiChildren)
            {
                if (child.Name == Form.Name)
                {
                    child.Activate();
                    return true;
                }
            }
            return false;
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            DevExpress.UserSkins.BonusSkins.Register();
            SkinHelper.InitSkinPopupMenu(barSubItem1);
            SkinHelper.InitSkinGallery(ribbonGalleryBarItem1);
            FrmDangNhap fdn = new FrmDangNhap();
            fdn.ShowDialog();

            if (fdn.dangnhapthanhcong == 1)
            {
                btnHanghoa.Enabled = true;
                btnKHNCC.Enabled = true;
                btnNhanvien.Enabled = true;
                btnLapPhieuChi.Enabled = true;
                btnLPT.Enabled = true;
                btnQLBANHANG.Enabled = true;
                btnQLNHAP.Enabled = true;

                btnDangnhap.Enabled = false;
                btnDangxuat.Enabled = true;
            }
            else
            {
                btnHanghoa.Enabled = false;
                btnKHNCC.Enabled = false;
                btnNhanvien.Enabled = false;
                btnLapPhieuChi.Enabled = false;
                btnLPT.Enabled = false;
                btnQLBANHANG.Enabled = false;
                btnQLNHAP.Enabled = false;

                btnDangxuat.Enabled = false;
                btnDangnhap.Enabled = true;

            }
        }

        private void btnHanghoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmQLHangHoa fhh = new FrmQLHangHoa();
            if (CheckExistForm(fhh)) return;
            fhh.MdiParent = this;
            fhh.Show();
        }

        private void btnKHNCC_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmQLNCC_KH fkh = new FrmQLNCC_KH();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

        private void btnNhanvien_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmQLNhanVien fnv = new FrmQLNhanVien();
            if (CheckExistForm(fnv)) return;
            fnv.MdiParent = this;
            fnv.Show();
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            //btnDangxuat.Enabled = true;
            //btnDangnhap.Enabled = false;
            //FrmDangNhap fdn = new FrmDangNhap();
            //fdn.ShowDialog();
            FrmMain_Load(sender, e);
        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (Form child in this.MdiChildren)
            {
                child.Close();
            }

            btnHanghoa.Enabled = false;
            btnKHNCC.Enabled = false;
            btnNhanvien.Enabled = false;
            btnLapPhieuChi.Enabled = false;
            btnLPT.Enabled = false;
            btnQLBANHANG.Enabled = false;
            btnQLNHAP.Enabled = false;
            //btnDangxuat.Enabled = false;
            //btnDangnhap.Enabled = true;
            //FrmDangNhap fdn = new FrmDangNhap();
            //fdn.ShowDialog();               
            FrmMain_Load(sender, e);
        }

        private void btnLPT_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmLapPhieuThu fkh = new FrmLapPhieuThu();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

        private void btnLapPhieuChi_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmLapPhieuChi fkh = new FrmLapPhieuChi();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

        private void btnQLBANHANG_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmQLBanHang fkh = new FrmQLBanHang();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

       

        private void btnThongtin_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmWelcome1 fm = new FrmWelcome1();
            if (CheckExistForm(fm)) return;
            fm.MdiParent = this;
            fm.Show();
        }

        private void btnQLNHAP_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmQLNhapHang f = new FrmQLNhapHang();
            if (CheckExistForm(f)) return;
            f.IsMdiContainer = false;
            f.MdiParent = this;
            f.Show();
        }

        private void barButtonItem1_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            FrmTKNV fkh = new FrmTKNV();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();

        }

        private void barButtonItem2_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            FrmTKKhachHang fkh = new FrmTKKhachHang();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmTKNCC fkh = new FrmTKNCC();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();

        }

        private void barButtonItem4_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmTKLoaiHang fkh = new FrmTKLoaiHang();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

        private void barButtonItem5_ItemClick(object sender, ItemClickEventArgs e)
        {
            FrmTKMatHang fkh = new FrmTKMatHang();
            if (CheckExistForm(fkh)) return;
            fkh.MdiParent = this;
            fkh.Show();
        }

       
    }
}